<?php
$system_dir = realpath(dirname(__FILE__) . '/../../') . '/';
$app_dir = $system_dir . 'apps';

$args = array_slice($argv, 1);

switch($args[0])
{
    case 'newapp':
        newApp($args[1]);
    break;
    
    default:
        die('unknown command: ' . $args[0] . ' / options: newapp <app name>' . "\n");
}




function newApp($page)
{
	global $app_dir;
    $cmd = "mkdir $app_dir/$page && ";
    $cmd .= "touch $app_dir/$page/views.php && ";
    $cmd .= "touch $app_dir/$page/models.php && ";
    $cmd .= "echo '<?php\n //models for $page' > $app_dir/$page/models.php && ";
    $cmd .= "echo '<?php\n //views for $page' > $app_dir/$page/views.php &&";
    $cmd .= "echo '<?php\n //forms for $page' > $app_dir/$page/forms.php";
    
    system($cmd, $retval);
    
    die($retval? $retval : '');
}